<?php
/**
 * Created by PhpStorm.
 * User: william
 * Date: 2017/6/21
 * Time: 10:40
 */
namespace Biz;
use Think\Exception;

class Fabulous extends \Base\BaseBiz{

    public function completeFabulous($article_id,$uid)
    {
        if (empty($article_id)) {
            return 'not null article_id';
        }
        try{
            $id = '';
            $fabulous_list = new \Orm\Fabulous\FabulousList();
            $fabulous_list['where'] = 'article_id = '.$article_id.' AND is_fabulous = 0';
            $fabulous_list->load();
            $count = count($fabulous_list['lists']);

            $fabulous_list['where'] = 'uid = '.$uid.' AND is_fabulous = 0 AND article_id='.$article_id;
            $fabulous_list['limit'] = '1';
            $fabulous_list->load();
            if ($fabulous_list['lists']) {
                $id = $fabulous_list['lists'][0]['id'];
            }
            return array(
                'sum_fabulous'=>$count,
                'fabulous_id'=>$id
            );
        }catch (\Exception $e){
            throw  new \Exception($e->getMessage());
        }
    }
}